package controller.admin;

import model.Type;
import service.TypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * 管理员后台展示类目管理
 */
@WebServlet(name = "AdminTypeListServlet", value = "/admin/type_list")
public class AdminTypeListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        TypeService ts = new TypeService();

        List<Type> typeList;
        HttpSession session = request.getSession();
        typeList = ts.getTypeList();
        session.setAttribute("list", typeList);
        request.getRequestDispatcher("type_list.jsp").forward(request, response);
    }
}
